package com.jlq.controller;

import com.jlq.pojo.Investor;
import com.jlq.service.InvestorService;
import com.jlq.vo.InvestorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Map;
/**
  *第一次测试
 */

@Controller
@RequestMapping("/investor")
public class InvestorController {
    //注入service层
    @Autowired
    private InvestorService investorService;

    //分页查询
    @ResponseBody
    @RequestMapping("/allByPage")
    public Map<String, Object> queryAllByPage(Integer page, Integer limit,String field, String type, String name){
        Map<String, Object> map = investorService.queryAllInvestor(page, limit, field, type, name);
        return map;
    }

    //添加
    @ResponseBody
    @RequestMapping("/add")
    public String add(InvestorVo investorVo, String code, String sname){
        String insert = investorService.insert(investorVo, code, sname);
        return insert;
    }

    //往session中添加id
    @ResponseBody
    @RequestMapping("/setUpdateId")
    public String setUpdateId(HttpSession session, Integer id){
        session.setAttribute("id", id);
        return "ok";
    }

    //根据id获取数据
    @ResponseBody
    @RequestMapping("/updInit")
    public Map<String, Object> updInit(HttpSession session){
        Integer id = (Integer)session.getAttribute("id");
        Map<String, Object> map = investorService.updateInit(id);
        return map;
    }

    //删除修改页面的已有股票
    @ResponseBody
    @RequestMapping("/delInvestorStock")
    public String delInvestorStock(Integer id, Integer stockId){
        String s = investorService.deleteInvestorStock(id, stockId);
        return s;
    }

    //修改
    @ResponseBody
    @RequestMapping("/upd")
    public String upd(Investor investor, String code, String sname){
        String s = investorService.update(investor, code, sname);
        return s;
    }
}
